﻿<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Keywords>
        <Keyword>dgnFile;Open;Create</Keyword>
      </Keywords>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
      <Title>DgnFile Load For Local File</Title>
      <Author>innovoCAD</Author>
      <Description>Create a DgnFile object for a local Dgn File that can be used to load parts of a file.</Description>
      <HelpUrl>
      </HelpUrl>
      <Shortcut>MSCEDgnFileLoadForLocalFile</Shortcut>
    </Header>
    <Snippet>
      <Imports>
        <Import>
          <Namespace>BDPN = Bentley.DgnPlatformNET</Namespace>
        </Import>
      </Imports>
      <References>
        <Reference>
          <Assembly>Bentley.DgnPlatformNET</Assembly>
        </Reference>
      </References>
      <Declarations>
      </Declarations>
      <Code Language="csharp" Kind="method body" Delimiter="$"><![CDATA[
//From DgnPlatformNet.chm help documentation
//Create a DgnFile object that can be used to load parts of a file.
//The DgnFileOwner object keeps the DgnFile open. A program that calls DgnFile.Create must hold reference
//to the DgnFileOwner object until it is finished with the DgnFile object.
//Then it must call Dispose on that object. If a program fails to Dispose of a DgnFileOwner object and the
//garbage collector invokes the Finalizer for that object, the Finalizer throws an exception.

BDPN.DgnDocument targetDgnDocument = BDPN.DgnDocument.CreateForLocalFile("dgnFilePath");
BDPN.DgnFileOwner dgnFileOwner = BDPN.DgnFile.Create(targetDgnDocument, BDPN.DgnFileOpenMode.ReadWrite);
System.IntPtr dgnFilePtr = dgnFileOwner.DgnFile.GetNative();
BDPN.DgnFile dgnFile = dgnFileOwner.DgnFile;
BDPN.StatusInt openForWriteStatus;
if (dgnFile.LoadDgnFile(out openForWriteStatus) == BDPN.DgnFileStatus.Success)
{
    //TODO: Add Code here for successfully loaded dgnFile.
     $end$
}

dgnFileOwner.Dispose();]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>